if !CLIENT then return end
print("PDMG - Starting Client Side ...")

local traceEntMaxHealth = 0;
local traceEntHealth = 0;
local traceEntPos = Vector( 0, 0, 0) 
local traceValid = false

print("PDMG - Creating Menu...")

local function OnPopulateToolPanel(panel)

	panel:AddControl("CheckBox", {
		Label = "Enable Prop Damage ?",
		Command = "pdmg_enabled",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Label", {
		Text = "Prop Destruction Effect (Visual Only)"
	})
	
	local combobox = {}
	combobox.Label = ""
	combobox.MenuButton = 0
	combobox.Options = {}
	combobox.Options["none"] = {pdmg_death_effect = ""}
	combobox.Options["Combine Ball Explosion"] = {pdmg_death_effect = "cball_explode"}
	combobox.Options["Antlion Gib Puff"] = {pdmg_death_effect = "AntlionGib"}
	combobox.Options["AR2Explosion"] = {pdmg_death_effect = "AR2Explosion"}
	combobox.Options["Blood Impact"] = {pdmg_death_effect = "BloodImpact"}
	combobox.Options["Combine Ball Bounce"] = {pdmg_death_effect = "cball_bounce"}
	combobox.Options["Explosion"] = {pdmg_death_effect = "Explosion"}
	combobox.Options["Water Splash"] = {pdmg_death_effect = "gunshotsplash"}
	combobox.Options["Gas Type Explosion"] = {pdmg_death_effect = "HelicopterMegaBomb"}
	combobox.Options["Manhack Sparks"] = {pdmg_death_effect = "ManhackSparks"}
	combobox.Options["Stunstick Impact"] = {pdmg_death_effect = "StunstickImpact"}
	combobox.Options["Thumper Dust"] = {pdmg_death_effect = "ThumperDust"}
	combobox.Options["Water Surface Explosion"] = {pdmg_death_effect = "WaterSurfaceExplosion"}
	combobox.Options["Balloon Pop (Confetti)"] = {pdmg_death_effect = "balloon_pop"}
	combobox.Options["Small Sparks"] = {pdmg_death_effect = "inflator_magic"}
	panel:AddControl("ComboBox", combobox)
		
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "Ragdoll Health Override",
		Command = "pdmg_ragdoll_health",
		Type = "Long",
		Min = "0",
		Max = "50000",
	})
	
	panel:AddControl("Label", {
		Text = "Ragdoll health Override. Ragdolls have a low calculated health. Enter a number in the box to override or enter 0 to use calclulated."
	})		
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "Prop Health Override",
		Command = "pdmg_override_health",
		Type = "Long",
		Min = "0",
		Max = "50000",
	})
	
	panel:AddControl("Label", {
		Text = "Prop Health Override will set all newly spawned props to specified Health, 0 Disables."
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
		
	panel:AddControl("CheckBox", {
		Label = "Use Volume in Health Calculations?",
		Command = "pdmg_use_volume",
	})
	
	panel:AddControl("CheckBox", {
		Label = "Use Mass in Health Calculations?",
		Command = "pdmg_use_mass",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Label", {
		Text = "NOTE: If you don't select either mass, volume or both, Prop Health will be a random fraction of the Prop's Mass."
	})
	
	panel:AddControl("Slider", {
		Label = "Prop Auto Heal",
		Command = "pdmg_autoheal",
		Type = "Long",
		Min = "0",
		Max = "10",
	})
	
	panel:AddControl("Label", {
		Text = "Automatically Heal Props by this much based on the set interval below, 0 Disables Auto Heal Props."
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "Prop Auto Heal Interval",
		Command = "pdmg_autoheal_interval",
		Type = "Float",
		Min = "0.0",
		Max = "10.0",
	})
	
	panel:AddControl("Label", {
		Text = "Interval at which props are auto healed in seconds. 0 is constant"
	})
	
	panel:AddControl("Label", {
		Text = ""
	})

	panel:AddControl("Slider", {
		Label = "Players Auto Heal",
		Command = "pdmg_autoheal_players",
		Type = "Long",
		Min = "0",
		Max = "10",
	})
	
	panel:AddControl("Label", {
		Text = "Automatically Heal Players by this much based on the set interval below, 0 Disables Auto Heal Players."
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "Players Auto Heal Interval",
		Command = "pdmg_autoheal_players_interval",
		Type = "Float",
		Min = "0.0",
		Max = "10.0",
	})
	
	panel:AddControl("Label", {
		Text = "Interval at which players are auto healed in seconds. 0 is constant"
	})
			
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "NPC Auto Heal",
		Command = "pdmg_autoheal_npcs",
		Type = "Long",
		Min = "0",
		Max = "10",
	})
	
	panel:AddControl("Label", {
		Text = "Automatically Heal NPCs by this much based on the set interval below, 0 Disables Auto Heal NPCs."
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "NPCs Auto Heal Interval",
		Command = "pdmg_autoheal_npcs_interval",
		Type = "Float",
		Min = "0.0",
		Max = "10.0",
	})
	
	panel:AddControl("Label", {
		Text = "Interval at which NPCs are auto healed in seconds. 0 is constant"
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Label", {
		Text = "When to show Prop Health on Screen:"
	})
	
	combobox = {}
	combobox.Label = ""
	combobox.MenuButton = 0
	combobox.Options = {}
	combobox.Options["Never"] = {pdmg_showhealth = "0"}
	combobox.Options["When Looking at it"] = {pdmg_showhealth = "1"}
	combobox.Options["Only When Using SWEP"] = {pdmg_showhealth = "2"}
	panel:AddControl("ComboBox", combobox)
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Break Constraints on Low Health?",
		Command = "pdmg_breakconstraints",
	})
	
	panel:AddControl("Slider", {
		Label = "Constraint Break Percent (in Decimal)",
		Command = "pdmg_breakconstraints_percent",
		Type = "Float",
		Min = "0.0",
		Max = "1.0",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Unfreeze Prop on Low Health?",
		Command = "pdmg_unfreeze",
	})
	
	panel:AddControl("Slider", {
		Label = "Unfreeze Percent (in Decimal)",
		Command = "pdmg_unfreeze_percent",
		Type = "Float",
		Min = "0.0",
		Max = "1.0",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Color Props Red With Damage?",
		Command = "pdmg_color_damage",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("Slider", {
		Label = "Health Multiplier",
		Command = "pdmg_health_multiplier",
		Type = "Float",
		Min = "0.0",
		Max = "1000.0",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Only Make prop_physics breakable.",
		Command = "pdmg_props_only",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Disable Damage On Wire Addon Stuff",
		Command = "pdmg_ex_wire",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Disable Damage On GMOD Base Stuff",
		Command = "pdmg_ex_gmod",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Disable Damage On Stargate Addon Stuff",
		Command = "pdmg_ex_stargate",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})

	panel:AddControl("CheckBox", {
		Label = "Disable Damage On PHX Explosives",
		Command = "pdmg_ex_phx_exp",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
	panel:AddControl("CheckBox", {
		Label = "Disable Damage on HL2 Explosives",
		Command = "pdmg_ex_hl2_exp",
	})
	
	panel:AddControl("Label", {
		Text = ""
	})
	
end

local function OnPopulateToolMenu()
	spawnmenu.AddToolMenuOption("Options", "Player", "PDMGSettings", "PDMG - Prop Damage", "", "", OnPopulateToolPanel, {SwitchConVar = 'pdmg_enabled'})
end
hook.Add("PopulateToolMenu", "PDMGToolMenu", OnPopulateToolMenu)

local function DrawHUD()
	
	if (traceValid) and (traceEntHealth > 0) then
		local percentCalc = 255 * (traceEntHealth / traceEntMaxHealth)
		draw.SimpleTextOutlined(tostring(traceEntHealth) .." / " ..tostring(traceEntMaxHealth), "MenuLarge", traceEntPos.x, traceEntPos.y, Color(255-percentCalc,percentCalc,0,255), 1, 1, 1, Color(0,0,0,255))
	end
	
end
hook.Add("HUDPaint", "PdmgHud", DrawHUD)

--Umsg Hook
local function entityInfo( data )

	traceValid = data:ReadBool()
	if !traceValid then return end
	traceEntHealth = data:ReadLong()
	traceEntMaxHealth = data:ReadLong()
	traceEntPos = data:ReadVector():ToScreen()
 
end
usermessage.Hook( "pdmgEntityHook", entityInfo );

print("PDMG - Finished Loading Client!")
print("... -=- ...")